package com.main.ok.push;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.greenline.gateway.base.ResponseDTO;
import com.greenline.gateway.service.weixin.WXTemplateMsgService;
import com.greenline.push.services.PushCenterCommonService;

public class PushMain {
    private static ExecutorService executors = Executors.newFixedThreadPool(8);

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        /**
         * 用户服务次数校验
         */
        PushCenterCommonService pushService = (PushCenterCommonService) ctx.getBean("pushService");
        // Map<String, String> tmp = new HashMap<String, String>();
        // tmp.put("mobile", "mobile");
        // tmp.put("email", "email");
        // tmp.put("content", "content");
        // tmp.put("source", "source");
        // for (int i = 0; i < 5000; i++) {
        // com.greenline.push.services.dto.ResponseDTO<Boolean> results =
        // pushService.send(11791783l, "10", tmp);
        // com.greenline.push.services.dto.ResponseDTO<Boolean> results2 =
        // pushService.send(11791784l, "10", tmp);
        // com.greenline.push.services.dto.ResponseDTO<Boolean> results3 =
        // pushService.send(11791785l, "10", tmp);
        // com.greenline.push.services.dto.ResponseDTO<Boolean> results13 =
        // pushService.send(11791783l, "8", tmp);
        // com.greenline.push.services.dto.ResponseDTO<Boolean> results11 =
        // pushService.send(11791784l, "8", tmp);
        // com.greenline.push.services.dto.ResponseDTO<Boolean> results12 =
        // pushService.send(11791785l, "8", tmp);
        // System.out.println(results.getMessage() + "--" +
        // results.getErrorMsg());
        // System.out.println(results1.getMessage() + "--" +
        // results1.getErrorMsg());
        // }

        // WXTemplateMsgService weixinServie = (WXTemplateMsgService)
        // ctx.getBean("wxTemplateMsgService");
        // ResponseDTO<Boolean> returns = weixinServie.sendTemplateMsg(null);
        // System.out.println(returns.getCode() + "-" + returns.getMessage());
        PushMain m = new PushMain();
        for (int i = 0; i < 10000; i++) {
            test t = m.new test(pushService);
            executors.execute(t);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        executors.shutdown();
        while (!executors.isTerminated()) {
        }
    }

    class test implements Runnable {
        private PushCenterCommonService service;

        public test(PushCenterCommonService service) {
            this.service = service;
        }

        @Override
        public void run() {
            Map<String, String> tmp = new HashMap<String, String>();
            // String content =
            // "{\"date\":1417516903822,\"media\":0,\"module\":\"chat\",\"test\":\"aaa\",\"userid\":\"123\"}";
            // String contents =
            // " {\"content\":\"aaa\",\"date\":1417574961848,\"media\":0,\"module\":\"chat\",\"rid\":\"12121334/doctor\",\"sid\":\"12121344/doctor\"}";
            // String ss =
            // "{\"content\":{\"address\":\"pushzuoshuai----301医院\",\"committeeId\":\"567\",\"date\":\"20040101\",\"doctorUserId\":\"456\",\"message\":\"用户版加号zuoshuai1111\",\"patientId\":\"345\",\"patientUserId\":\"234\",\"type\":\"1\"},\"date\":1417575187807,\"media\":0,\"module\":\"push_apply_notify\",\"userid\":\"123\"}";
            String ss = "hello,java---fei";
            // tmp.put("first", "testtzuoshuai");
            // tmp.put("patientName", "testtzuoshuai");
            // tmp.put("patientSex", "testtzuoshuai");
            // tmp.put("hospitalName", "testtzuoshuai");
            // tmp.put("department", "testtzuoshuai");
            // tmp.put("doctor", "testtzuoshuai");
            // tmp.put("seq", "testtzuoshuai");
            // tmp.put("remark", "testtzuoshuai");

            tmp.put("first", "testtzuoshuai");
            tmp.put("keynote1", "testtzuoshuai");
            tmp.put("keynote2", "testtzuoshuai");

            tmp.put("keynote3", "testtzuoshuai");
            tmp.put("keynote4", "testtzuoshuai");
            tmp.put("remark", "testtzuoshuai");
            tmp.put("url", "http://www.baidu.com");
            // tmp.put("content", ss);
            tmp.put("content", "this message is from push-center.-->zuoshuai");
            // tmp.put("content",
            // "this message is from push-center.-->zuoshuai");
            tmp.put("title", "hello,thx");
            // tmp.put("source", "source");
            // tmp.put("test", "xx");
            // tmp.put("first", "this is the first msg in test!!!");
            // tmp.put("keyword1", "here is key1");
            // tmp.put("keyword2", "here is key2");
            // tmp.put("remark", "zuoshuai-remark");
            // tmp.put("contactMobile", "13291872722");
            // tmp.put("contactMail", "zuoshuai@guahao.com");

            for (int i = 0; i < 1; i++) {
                // zuoshuai::;5560966
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.send(6339755l, "13", "8", tmp);
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.send(11791781l, "13", "8", tmp);//weixin
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.send(5560966l, "16", "16", tmp); // sms
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.sendGroup(11l, "13", "9", tmp); // sms
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.send(11791844l, "16", "16", tmp); // email
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.sendDomain("16", "16", tmp);
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.send(12122374l, "cancleTeamplate", "weixinWujin",
                // tmp, null); // echat
                List<Long> userlist = new ArrayList<Long>();
                userlist.add(12549300l);
                // userlist.add(12549305l);
                // userlist.add(12549310l);

                com.greenline.push.services.dto.ResponseDTO<Boolean> results = service.sendList(userlist, "echatCommonPushTemplate",
                        "echat_relative_domain", tmp, null); // echat
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.send(12121343l, "16", "16", tmp); // apns
                /**
                 * 7 建群
                 */
                // com.greenline.push.services.dto.ResponseDTO<Long> results =
                // service.createGroup("zuoshuai-group-dev2", 5560966l);
                /**
                 * 订阅
                 */
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.subscribe(16l, 5560966l);
                /**
                 * 批量订阅
                 */
                // List<Long> userids = new ArrayList<Long>();
                // userids.add(11792341l);
                // userids.add(12121343l);
                // userids.add(12121252l);
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.subscribe(16l, userids);
                /**
                 * 取消订阅
                 */
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.unsubscribe(16l, 55609616l);
                /**
                 * 群推送
                 */
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results
                // = service.sendGroup(16l, "16", "17", tmp);
                /**
                 * 获取定义
                 */
                // com.greenline.push.services.dto.ResponseDTO<String> results =
                // service.getBizDefine("weiyi-patient");
                // System.out.println(cResult.getCode() + cResult.getMessage() +
                // "--" + cResult.getErrorMsg());
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results2
                // = service.send(11791784l, "10", tmp);
                // com.greenline.push.services.dto.ResponseDTO<Boolean> results3
                // = service.send(11791785l, "10", tmp);
                System.out.println(Thread.currentThread().getName() + "[>>>]" + results.getMessage() + "--" + results.getErrorMsg() + "=="
                        + results.getDataResult());
            }
        }

    }
}
